class_name PlayerStateBicycleKick
extends PlayerState

const BALL_HEIGHT_MIN :=1.0
const BALL_HEIGHT_MAX := 30.0
const BONUS_POWER := 1.3

func _enter_tree() -> void:
	animation_player.play("bicycle_kick")
	ball_detection_area.body_entered.connect(on_ball_entered.bind())
	
#func _process(delta: float) -> void:
func on_ball_entered(contact_ball: Ball) -> void:
	if ball.can_air_connect(BALL_HEIGHT_MIN,BALL_HEIGHT_MAX):
		var destination := target_goal.get_random_target_position()
		var direction := ball.position.direction_to(destination)
		SoundPlayer.play(SoundPlayer.Sound.POWERSHOT)
		ball.shoot(direction * player.Power * BONUS_POWER)

func on_animation_complete() ->void:
	transaction_state(Player.State.RECOVERING)
